//
//  SettingViewController.m
//  iTimeline
//
//  Created by Mobioneer HV 04 on 1/7/13.
//  Copyright (c) 2013 Mobioneer Co., Ltd. All rights reserved.
//

#import "SettingViewController.h"
#import "LoginView.h"

#import "Help.h"
#import "About.h"
#import "ChangeDefaultSound.h"

@interface SettingViewController ()

@end

@implementation SettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        title = [NSMutableArray new];
        value1 = [NSMutableArray new];
        value2 = [NSMutableArray new];
        // Custom initialization
        
        [title addObject:@"Change Pass Code"];
        [title addObject:@"Information"];
        // Custom initializatio
        [value1 addObject:@"Change passcode"];
        [value1 addObject:@"Change default sound"];
        [value2 addObject:@"Share"];
        [value2 addObject:@"Help"];
        [value2 addObject:@"About"];
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [self setTableView:nil];
    [super viewDidUnload];
}



//table view
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return  30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return [value1 count];
    }
    else return [value2 count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [title objectAtIndex:section];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [title count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
        
        
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = [value1 objectAtIndex:indexPath.row];
    }
    else
        cell.textLabel.text = [value2 objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellStyleValue1;
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row ==0) {
        LoginView *bk =[[LoginView alloc] initWithNibName:@"LoginView" action:@"changepass" passcode:nil bundle:nil];
        bk.count =1;
        bk.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
        [self.navigationController pushViewController:bk animated:YES];
    }
    if (indexPath.section == 1 && indexPath.row ==0) {
        UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle: @"Share with Facebook" otherButtonTitles:@"Share with Twitter" ,nil];
        popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        [popupQuery showInView:self.view];
    }
    if(indexPath.section ==1 && indexPath.row == 1)
    {
        Help *he = [[Help alloc] initWithNibName:@"Help" bundle:nil];
        [self.navigationController pushViewController:he animated:YES];
    }
    if(indexPath.section ==1 && indexPath.row == 2)
    {
        About *a= [[About alloc] initWithNibName:@"About" bundle:nil];
        [self.navigationController pushViewController:a animated:YES];
    }
    if (indexPath.section ==0 && indexPath.row ==1 ) {
        ChangeDefaultSound *change =[[ChangeDefaultSound alloc] initWithNibName:@"ChangeDefaultSound" bundle:nil];
        [self.navigationController pushViewController:change animated:YES];
    }
}
-(void) cancel
{
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        //share face
        NSLog(@"phim0");
    } else
        if (buttonIndex == 1) {
            //share twi
            NSLog(@"phim1");
        }
        else
            if (buttonIndex == 2) {
                //cacel
                NSLog(@"phim2");
            }
    
}

@end
